package com.maila.calltaxi.ui;

import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeAddress;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.maila.calltaxi.R;
import com.maila.calltaxi.data.Order;
import com.maila.calltaxi.data.Status;
import com.maila.calltaxi.utils.AudioRecoderUtils;
import com.maila.calltaxi.utils.DateTFormat;
import com.maila.calltaxi.utils.PopupWindowFactory;
import com.maila.calltaxi.utils.StartActivityUtils;
import com.maila.calltaxi.utils.TimeUtils;
import com.maila.calltaxi.utils.ToastUtil;
import com.maila.calltaxi.view.ChangeClintPop;
import com.maila.calltaxi.view.PushOrderPop;
import com.maila.calltaxi.view.WaitCarPop;
import com.maila.calltaxi.view.timepicker.TimeSelectUtils;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class AmapActivity extends AppCompatActivity implements WaitCarPop.ActionListener,Status.StatusListener,AMapLocationListener, AMap.OnCameraChangeListener, ChangeClintPop.ChangeClinetListener, LocationSource, GeocodeSearch.OnGeocodeSearchListener {
    @BindView(R.id.header)
    ImageView header;
    @BindView(R.id.tv_driver_name)
    TextView tvDriverName;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.taxi_carcode)
    TextView taxiCarcode;
    @BindView(R.id.btn_call_the_taxi)
    ImageView btnCallTheTaxi;
    @BindView(R.id.current_hint)
    TextView currentHint;
    @BindView(R.id.ll_taxi_info)
    AutoLinearLayout llTaxiInfo;
    @BindView(R.id.current_time)
    TextView currentTime;
    @BindView(R.id.current_journey)
    TextView currentJourney;
    @BindView(R.id.current_fee)
    TextView currentFee;
    @BindView(R.id.ll_travel_info)
    AutoLinearLayout llTravelInfo;
    @BindView(R.id.map)
    MapView mapView;
    @BindView(R.id.time_count)
    TextView timeCount;
    @BindView(R.id.cv_search_car)
    CardView cvSearchCar;
    @BindView(R.id.tv_go_time)
    TextView tvGoTime;
    @BindView(R.id.ll_change_time)
    AutoLinearLayout llChangeTime;
    @BindView(R.id.tv_clint_name)
    TextView tvClintName;
    @BindView(R.id.ll_change_clint)
    AutoLinearLayout llChangeClint;
    @BindView(R.id.location)
    TextView tvCurLocation;
    @BindView(R.id.destination)
    TextView tvDestination;
    @BindView(R.id.rl_destination)
    AutoRelativeLayout rlDestination;
    @BindView(R.id.cancle_the_order)
    TextView cancleTheOrder;
    @BindView(R.id.tousu)
    TextView tousu;
    @BindView(R.id.cancle_order)
    TextView cancleOrder;
    @BindView(R.id.ll_car_comming_menu)
    AutoLinearLayout llCarCommingMenu;
    @BindView(R.id.container)
    FrameLayout containerLayout;
    @BindView(R.id.root_rl)
    RelativeLayout rl;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.guide_view)
    ImageView guide_view;
    private AMap aMap;
    private LocationManagerProxy mLocationManagerProxy;
    private Handler handler = new Handler();
    private OnLocationChangedListener listener;
    private LatLng myLocation = null;
    private Marker centerMarker,sijiMarker;
    private boolean isMovingMarker = false;
    private BitmapDescriptor movingDescriptor, chooseDescripter, successDescripter;
    private ValueAnimator animator = null;
    private GeocodeSearch geocodeSearch;


    private ImageView ivCircle;

    static final int VOICE_REQUEST_CODE = 66;

    private ImageView mImageView;
    private TextView mTextView;
    private AudioRecoderUtils mAudioRecoderUtils;
    private Context context;
    private PopupWindowFactory mPop;
    PushOrderPop pushOrderPop;
    ChangeClintPop.ChangeClinetListener changelistener;
    ChangeClintPop changeClintPop;
    int status=0;//0为未叫车 1 为发出叫车请求 等待中  2为 收到司机回应 被接单 但未上车  3 为已上车
    Status statusvar;

    int next=0;//假数据效果  后续删掉
    WaitCarPop waitCarPop;
    private int countdown = 59;
    Timer mTimer;
    boolean isSendSuccess = false; //发出叫车请求

    private Handler mHandler = new Handler() {

        public void handleMessage(Message msg) {
            if (msg.what == 12) {
                isSendSuccess = false;
                timeCount.setText("00:00");
                if (mTimer != null) {
                    mTimer.cancel();
                    mTimer = null;
                }
                waitCarPop.showAtLocation(getWindow().getDecorView(),Gravity.CENTER,0,0);
            } else {
                if(msg.what>9){
                    timeCount.setText("00:"+msg.what );
                }else {
                    timeCount.setText("00:0"+msg.what );
                }

            }
        }
    };

    private Handler uiHandler = new Handler() {

        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 0:
                    next=0;
                    if(sijiMarker!=null){
                        sijiMarker.remove();
                    }
                    if (mTimer != null) {
                        mTimer.cancel();
                        mTimer = null;
                    }
                    tvTitle.setText("附近有约2辆可用出租车");
                    cvSearchCar.setVisibility(View.GONE);
                    cancleTheOrder.setVisibility(View.GONE);
                    llTravelInfo.setVisibility(View.GONE);
                    llTaxiInfo.setVisibility(View.GONE);
                    llCarCommingMenu.setVisibility(View.GONE);
                    rlDestination.setVisibility(View.VISIBLE);
                    break;
                case 1:
                    cvSearchCar.setVisibility(View.VISIBLE);
                    cancleTheOrder.setVisibility(View.VISIBLE);
                    rlDestination.setVisibility(View.GONE);
                    getimecount();
                    break;
                case 2:
                    llTaxiInfo.setVisibility(View.VISIBLE);
                    llCarCommingMenu.setVisibility(View.VISIBLE);
                    rlDestination.setVisibility(View.GONE);
                    cvSearchCar.setVisibility(View.GONE);
                    cancleTheOrder.setVisibility(View.GONE);
                    llTravelInfo.setVisibility(View.GONE);

                    tvTitle.setText("请稍候，司机正在赶来接您");
                    tousu.setText("投诉");
                    cancleOrder.setVisibility(View.VISIBLE);
                    addMarker(myLocation,"假司机的位置");

                    demoexemple(1);
                    break;
                case 3:
                    llTravelInfo.setVisibility(View.VISIBLE);
                    rlDestination.setVisibility(View.GONE);
                    cvSearchCar.setVisibility(View.GONE);
                    cancleTheOrder.setVisibility(View.GONE);
                    llTaxiInfo.setVisibility(View.GONE);
                    llCarCommingMenu.setVisibility(View.VISIBLE);
                    tvTitle.setText("稍作休息，马上到目的地");
                    tousu.setText("申诉");
                    cancleOrder.setVisibility(View.GONE);
                    demoexemple(2);
                    break;
                default:
                    break;

            }

        }
    };
    private int step=1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_amap);
        ButterKnife.bind(this);
        mapView.onCreate(savedInstanceState);
        context = this;
        changelistener = this;
        statusvar=Status.getInstance();
        statusvar.setBroadListener(this);
        initUI();
        initAmap();
        setUpLocationStyle();
    }

    private void initUI() {
        toolbar.setTitle("闪滴出行");
        toolbar.setTitleTextColor(Color.WHITE);
        setSupportActionBar(toolbar);
//
        changeClintPop = new ChangeClintPop(this, changelistener);
        //PopupWindow的布局文件
        final View view = View.inflate(this, R.layout.layout_microphone, null);

        mPop = new PopupWindowFactory(this, view);

        //PopupWindow布局文件里面的控件
        mImageView = (ImageView) view.findViewById(R.id.iv_recording_icon);
        mTextView = (TextView) view.findViewById(R.id.tv_recording_time);
        mAudioRecoderUtils = new AudioRecoderUtils();

        waitCarPop=new WaitCarPop(AmapActivity.this, this);

        //录音回调
        mAudioRecoderUtils.setOnAudioStatusUpdateListener(new AudioRecoderUtils.OnAudioStatusUpdateListener() {

            //录音中....db为声音分贝，time为录音时长
            @Override
            public void onUpdate(double db, long time) {
                mImageView.getDrawable().setLevel((int) (3000 + 6000 * db / 100));
                mTextView.setText(TimeUtils.long2String(time));
            }

            //录音结束，filePath为保存路径
            @Override
            public void onStop(String filePath) {
//                Toast.makeText(context, "录音保存在：" + filePath, Toast.LENGTH_SHORT).show();
                Order order = new Order();
                order.setDate(DateTFormat.date4String(new Date()));
                order.setPositions(tvCurLocation.getText().toString());
                order.setClintname("马先生");
                order.setClintphone("13864699096");
                order.setRecord(filePath);
                pushOrderPop = new PushOrderPop(AmapActivity.this, order, new PushOrderPop.CallCarListener() {
                    @Override
                    public void sendcall(Order order) {
                        //// TODO: 2017/7/12 调接口 发出叫车请求
                        status=1;
                        statusvar.setVar(status);
                    }
                });
                pushOrderPop.showAtLocation(AmapActivity.this.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
                //PopupWindow布局文件里面的控件
                mTextView.setText(TimeUtils.long2String(0));
            }
        });
        StartListener();

        //6.0以上需要权限申请
        requestPermissions();
        introAnimPrepare();
    }

    /**
     * 开启扫描之前判断权限是否打开
     */
    private void requestPermissions() {
        //判断是否开启摄像头权限
        if ((ContextCompat.checkSelfPermission(context,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) &&
                (ContextCompat.checkSelfPermission(context,
                        Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED)&&(ContextCompat.checkSelfPermission(context,
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)&&(ContextCompat.checkSelfPermission(context,
                Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED)
                ) {
            StartListener();

            //判断是否开启语音权限
        } else {
            ActivityCompat.requestPermissions((Activity) context,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.CALL_PHONE}, VOICE_REQUEST_CODE);
        }

    }

    /**
     * 请求权限回调
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == VOICE_REQUEST_CODE) {
            if ((grantResults[0] == PackageManager.PERMISSION_GRANTED) && (grantResults[1] == PackageManager.PERMISSION_GRANTED)&&(grantResults[2] == PackageManager.PERMISSION_GRANTED)&&(grantResults[3] == PackageManager.PERMISSION_GRANTED)) {
                StartListener();
                introAnimPrepare();
                initAmap();
                setUpLocationStyle();
            } else {
                Toast.makeText(context, "请开启所有权限,以便您正常使用闪滴", Toast.LENGTH_SHORT).show();
            }
        }
    }


    public void StartListener() {
        //Button的touch监听
        tvDestination.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction()) {

                    case MotionEvent.ACTION_DOWN:
                        requestPermissions();
                        mPop.showAtLocation(rl, Gravity.CENTER, 0, 0);

//                        tvDestination.setText("");
                        mAudioRecoderUtils.startRecord();


                        break;

                    case MotionEvent.ACTION_UP:

                        mAudioRecoderUtils.stopRecord();        //结束录音（保存录音文件）
//                        mAudioRecoderUtils.cancelRecord();    //取消录音（不保存录音文件）
                        mPop.dismiss();
//                        tvDestination.setText("");

                        break;
                    case MotionEvent.ACTION_HOVER_MOVE:
                        mAudioRecoderUtils.cancelRecord();    //取消录音（不保存录音文件）
                        mPop.dismiss();
//                        tvDestination.setText("");
                        break;
                }
                return true;
            }
        });
    }

    private void initAmap() {
        if (aMap == null) {
            aMap = mapView.getMap();
        }
        aMap.setLocationSource(this);// 设置定位监听
        aMap.setMyLocationEnabled(true);
        aMap.getUiSettings().setZoomControlsEnabled(false);

        aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
        CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(15);
        aMap.moveCamera(cameraUpdate);

        movingDescriptor = BitmapDescriptorFactory.fromResource(R.mipmap.chengchesuozaidi);
        chooseDescripter = BitmapDescriptorFactory.fromResource(R.mipmap.shoudongxuanze);
        successDescripter = BitmapDescriptorFactory.fromResource(R.mipmap.shoudongxuanze);

        geocodeSearch = new GeocodeSearch(this);
        geocodeSearch.setOnGeocodeSearchListener(this);

    }

    private void setUpLocationStyle() {
        // 自定义系统定位蓝点
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.
                fromResource(R.mipmap.dangqianweizhi));
        myLocationStyle.strokeWidth(0);
        myLocationStyle.radiusFillColor(Color.TRANSPARENT);
        aMap.setMyLocationStyle(myLocationStyle);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
        deactivate();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    protected void onDestroy() {
        mapView.onDestroy();
        containerLayout.removeView(ivCircle);
        super.onDestroy();
    }

    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        if (aMapLocation != null && aMapLocation.getAMapException().getErrorCode() == 0) {
            if (listener != null) {
                listener.onLocationChanged(aMapLocation);// 显示系统小蓝点
            }
            myLocation = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
            tvCurLocation.setText(aMapLocation.getRoad() + aMapLocation.getStreet() + aMapLocation.getPoiName());
            addChooseMarker();
        }
    }

    private void addChooseMarker() {
        MarkerOptions centerMarkerOption = new MarkerOptions().position(myLocation).icon(chooseDescripter);
        centerMarker = aMap.addMarker(centerMarkerOption);
        centerMarker.setPositionByPixels(mapView.getWidth() / 2, mapView.getHeight() / 2);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                CameraUpdate update = CameraUpdateFactory.zoomTo(17f);
                aMap.animateCamera(update, 1000, new AMap.CancelableCallback() {
                    @Override
                    public void onFinish() {
                        aMap.setOnCameraChangeListener(AmapActivity.this);
                    }

                    @Override
                    public void onCancel() {
                    }
                });
            }
        }, 1000);
    }

    @Override
    public void onLocationChanged(Location location) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void activate(OnLocationChangedListener onLocationChangedListener) {
        listener = onLocationChangedListener;
        mLocationManagerProxy = LocationManagerProxy.getInstance(this);
        mLocationManagerProxy.requestLocationData(
                LocationProviderProxy.AMapNetwork, -1, 100, this);
    }

    public void deactivate() {
        if (mLocationManagerProxy != null) {
            mLocationManagerProxy.removeUpdates(this);
            mLocationManagerProxy.destroy();
        }
        mLocationManagerProxy = null;
    }

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        if (centerMarker != null) {
            setMovingMarker();
        }
    }

    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        LatLonPoint point = new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude);
        RegeocodeQuery query = new RegeocodeQuery(point, 50, GeocodeSearch.AMAP);
        geocodeSearch.getFromLocationAsyn(query);
        if (centerMarker != null) {
            animMarker();
        }
        showLocationView();
    }


    /**
     * 往地图上添加marker
     *
     * @param latLng
     */
    private void addMarker(LatLng latLng, String desc) {
        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.position(latLng);
        markerOptions.title("[司机的位置]");
        markerOptions.snippet(desc);
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.siji));
        sijiMarker = aMap.addMarker(markerOptions);
    }


    private void setMovingMarker() {
        if (isMovingMarker)
            return;

        isMovingMarker = true;
        centerMarker.setIcon(movingDescriptor);
        hideLocationView();
    }

    private void animMarker() {
        isMovingMarker = false;
        if (animator != null) {
            animator.start();
            return;
        }
        animator = ValueAnimator.ofFloat(mapView.getHeight() / 2, mapView.getHeight() / 2 - 30);
        animator.setInterpolator(new DecelerateInterpolator());
        animator.setDuration(150);
        animator.setRepeatCount(1);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Float value = (Float) animation.getAnimatedValue();
                centerMarker.setPositionByPixels(mapView.getWidth() / 2, Math.round(value));
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                centerMarker.setIcon(chooseDescripter);

            }
        });
        animator.start();
    }

    private void endAnim() {
        if (animator != null && animator.isRunning())
            animator.end();
    }

    @Override
    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
        if (i == 0) {
            if (regeocodeResult != null && regeocodeResult.getRegeocodeAddress() != null) {
                endAnim();
                centerMarker.setIcon(successDescripter);
                RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress();
                String formatAddress = regeocodeResult.getRegeocodeAddress().getFormatAddress();
                String shortAdd = formatAddress.replace(regeocodeAddress.getProvince(), "").replace(regeocodeAddress.getCity(), "").replace(regeocodeAddress.getDistrict(), "");
                tvCurLocation.setText(shortAdd);
            } else {
                ToastUtil.show(AmapActivity.this, R.string.no_result);
            }
        } else {
            ToastUtil.show(AmapActivity.this, R.string.error_network);
        }
    }

    @Override
    public void onGeocodeSearched(GeocodeResult geocodeResult, int rCode) {
    }

    private void introAnimPrepare() {
        toolbar.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                toolbar.getViewTreeObserver().removeOnPreDrawListener(this);
                toolbar.setTranslationY(-toolbar.getHeight());
                return false;
            }
        });
        ivCircle = new ImageView(this);
        ivCircle.setImageResource(R.drawable.tunahome_imageview_bottom);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER;
        containerLayout.addView(ivCircle, params);
        ivCircle.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                ivCircle.getViewTreeObserver().removeOnPreDrawListener(this);
                ivCircle.setTranslationY(containerLayout.getHeight() / 2 - ivCircle.getHeight());
                ivCircle.setScaleX(2f);
                ivCircle.setScaleY(2f);
                return false;
            }
        });
        containerLayout.post(new Runnable() {
            @Override
            public void run() {
                animIntroduce();
            }
        });
    }

    private void animIntroduce() {
        ObjectAnimator animToolbar = ObjectAnimator.ofFloat(toolbar, "TranslationY", 0f);
        animToolbar.setDuration(300);
        ObjectAnimator animCircle = ObjectAnimator.ofFloat(ivCircle, "TranslationY", 0);
        animCircle.setDuration(400);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(ivCircle, "ScaleX", 1f);
        scaleX.setDuration(400);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(ivCircle, "ScaleY", 1f);
        scaleY.setDuration(400);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animToolbar, animCircle, scaleX, scaleY);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                containerLayout.removeView(ivCircle);
                mapView.setVisibility(View.VISIBLE);
                if(status==0){
                    tvCurLocation.setVisibility(View.VISIBLE);
                    rlDestination.setVisibility(View.VISIBLE);
                }

            }
        });
        animatorSet.start();
    }

    private void hideLocationView() {
        ObjectAnimator animLocation = ObjectAnimator.ofFloat(tvCurLocation, "TranslationY", -tvCurLocation.getHeight() * 2);
        ObjectAnimator animDestinatiion = ObjectAnimator.ofFloat(rlDestination, "TranslationY", rlDestination.getHeight() * 2);
        AnimatorSet set = new AnimatorSet();
        set.playTogether(animDestinatiion, animLocation);
        set.setDuration(200);
        set.start();
    }

    private void showLocationView() {
        ObjectAnimator animLocation = ObjectAnimator.ofFloat(tvCurLocation, "TranslationY", 0);
        ObjectAnimator animDestinatiion = ObjectAnimator.ofFloat(rlDestination, "TranslationY", 0);
        AnimatorSet set = new AnimatorSet();
        set.playTogether(animDestinatiion, animLocation);
        set.setDuration(200);
        set.start();
    }

    @OnClick({R.id.main_menu, R.id.btn_call_the_taxi, R.id.guide_view,R.id.ll_change_time, R.id.ll_change_clint, R.id.myLocation, R.id.cancle_the_order, R.id.tousu, R.id.cancle_order})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.guide_view:
                if (step==1){
                    step=2;
                    guide_view.setImageResource(R.mipmap.step2);
                }else  if(step==2){
                    step=3;
                    guide_view.setImageResource(R.mipmap.step3);
                }else {
                    step=3;
                    guide_view.setVisibility(View.GONE);
                }
                break;
            case R.id.main_menu:
                StartActivityUtils.start(context, SettingActivity.class);
                break;
            case R.id.btn_call_the_taxi:
                break;
            case R.id.ll_change_time:
                TimeSelectUtils timeSelectUtils = new TimeSelectUtils(AmapActivity.this, null, new TimeSelectUtils.GetSubmitTime() {
                    @Override
                    public void selectTime(String data) {
                        Toast.makeText(AmapActivity.this, data, Toast.LENGTH_SHORT).show();
                        if(!data.equals("现在")){
                            tvGoTime.setText("预约: " + data);
                        }

                    }
                });

                timeSelectUtils.dateTimePicKDialog();
                break;
            case R.id.ll_change_clint:
                changeClintPop.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0);
                break;
            case R.id.myLocation:
                CameraUpdate update = CameraUpdateFactory.changeLatLng(myLocation);
                aMap.animateCamera(update);
                break;
            case R.id.cancle_the_order:
                status=0;
                isSendSuccess=false;
                statusvar.setVar(status);
                break;
            case R.id.tousu:
                if(status==2){

                }else if(status==3){

                }
                break;
            case R.id.cancle_order:
                status=0;
                statusvar.setVar(status);
                break;
        }
    }

    /**
     * 修改乘车人
     *
     * @param num
     */
    @Override
    public void editphonenum(String num) {
        tvClintName.setText("尾号" + num.substring(num.length() - 4, num.length()));
    }

    /**
     * 当前状态
     * @param status
     */
    @Override
    public void changeStatus(int status) {
        uiHandler.sendEmptyMessage(status);
    }

    private void demoexemple(final int type) {
        countdown = 5;
        mTimer = new Timer();
        mTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (countdown >= 0) {
                    countdown--;
                }else {
                    if (mTimer != null) {
                        mTimer.cancel();
                        mTimer = null;
                    }
                    if(type==1){
                        status=3;
                        statusvar.setVar(status);
                    }else {
                        status=0;
                        statusvar.setVar(status);
                        StartActivityUtils.start(context,PayActivity.class);
                    }
                }
            }
        }, 0, 1000);
    }

    private void getimecount() {
        if (!isSendSuccess) {
            countdown = 0;
            mTimer = new Timer();
            mTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (countdown <=12) {
                        mHandler.sendEmptyMessage(countdown);
                        countdown++;
                    }
                }
            }, 0, 1000);
        }
    }

    @Override
    public void waitorcancle(int action) {
        if(action==0){
            status=0;
            statusvar.setVar(status);
        }else {
            ++next;
            if(next==1){
                status=2;
                statusvar.setVar(status);
            }else {
                getimecount();
            }
        }
    }
}
